<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="plugins/elementui/index.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/config.js"></script>
    <script src="js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <div class="login-container">
        <div class="loginBox">
            <form method="post" class="login-form" action="/user/login" label-position="left">
                <div class="title-container">
                    <div class="logoInfo clearfix">
                        <em class="logo"></em>
                    </div>
                </div>
                <div>
                        <span class="svg-container svg-container_login">
                          <span class="user"></span>
                        </span>
                    <input v-model="user.username" type="text" name="username" placeholder="请输入用户名"/>
                </div>

                <div>
                        <span class="svg-container">
                          <span class="username"></span>
                        </span>
                    <input v-model="user.password" type="password" name="password" placeholder="请输入密码"/>
                </div>
                <input type="button" style="width:100%;margin-bottom:30px;" value="登录" @click="login()"></input>
            </form>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="plugins/elementui/vue.js"></script>
<script src="plugins/elementui/index.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            user: {
                username: '',
                password: ''
            }
        },
        methods: {
            login() {  //formName就是传递过来的'loginForm'值，通过loginForm就可以找到form表单对象
                // 为表单绑定验证功能,//validate()表示的是校验的方法，valid表示校验结果
                axios.post("/user/login", this.user).then(resp => {
                    if (resp.data.flag) {
                        // 跳转到index.html页面
                        location.href = "index.html";
                    } else {
                        //失败
                        alert("用户名获取密码错误!");
                    }
                });
            }

        }
    });


</script>
</html>
